package com.ymatou.iapi.accounting.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.accounting.parameter.*;
import com.ymatou.iapi.accounting.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.Account;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*根据用户编号获取其所有的账户列表接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAccountListByUserId{
	private static GetAccountListByUserIdBean getaccountlistbyuseridBean;
	private static GetAccountListByUserIdCall getaccountlistbyuseridCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户编号获取其所有的账户列表接口");
	}

	@Before
	public void caseUp() {
		getaccountlistbyuseridBean=new GetAccountListByUserIdBean();
		getaccountlistbyuseridCall=new GetAccountListByUserIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaccountlistbyuseridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAccountListByUserId_001() {
		Logger.start(true,"根据用户编号获取账户列表成功");
		try {
			int userId=21000003;
			getaccountlistbyuseridBean.setUserId(userId);
			getaccountlistbyuseridBean.setAppId("AutoTest");
			getaccountlistbyuseridCall.setData(getaccountlistbyuseridBean);
			getaccountlistbyuseridCall.callService();			
			//查询数据库
			List<Account> aids= new AccountWapper().selectAccountInfoByUserId(userId);			
			//接口返回数据
			ArrayList<AccountBean> account=getaccountlistbyuseridCall.getReturnAccountList();	
		
			Logger.comment("接口返回记录数::"+account.size());
			//将接口返回的数据跟数据库进行比较
			if (account.size()>0){
				for(int i=0;i<account.size();i++){	
					Logger.comment("第"+(i+1)+"条记录");

					Logger.verifyEquals((Integer)aids.get(0).getUserId(),account.get(i).getUserId(),"验证接口返回userid跟数据库是否一致");	
					Logger.verifyEquals((Integer)aids.get(0).getStatus(),account.get(i).getStatus(),"验证接口返回Action跟数据库是否一致");	
					Logger.verifyEquals((Integer)aids.get(0).getCurrencyType(),account.get(i).getCurrencyType(),"验证接口返回CurrencyType跟数据库是否一致");	
					Logger.verifyEquals((Integer)aids.get(0).getAccountType(),account.get(i).getAccountType(),"验证接口返回AccountType跟数据库是否一致");	
					Logger.verifyEquals(0,((BigDecimal)aids.get(0).getAvailAmount()).compareTo(account.get(i).getAvailAmount()),"验证接口返回AvailAmount:"+account.get(i).getAvailAmount()+"跟数据库是否一致");
					Logger.verifyEquals(0,((BigDecimal)aids.get(0).getFreezeAmount()).compareTo(account.get(i).getFreezeAmount()),"验证接口返回FreezeAmount:"+account.get(i).getFreezeAmount()+"跟数据库是否一致");			
					Logger.verifyEquals((String)aids.get(0).getAccountId(),account.get(i).getAccountId(),"验证接口返回AccountInfoId跟数据库是否一致");			
					
					String ct=YMTDateUtil.getFormatTime(aids.get(0).getCreateTime(), YMTDateUtil.YMDHMSS);
					Logger.verifyEquals(ct.substring(0, 19), account.get(i).getCreateTime().substring(0, 19),
							"验证接口返回CreateTime跟数据库是否一致");
					String ut=YMTDateUtil.getFormatTime(aids.get(0).getUpdateTime(), YMTDateUtil.YMDHMSS);
					Logger.verifyEquals(ut.substring(0, 19), account.get(i).getUpdateTime().substring(0, 19),
							"验证接口返回UpdateTime跟数据库是否一致");
				}						
			}			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountListByUserId_002() {
		Logger.start(false,"用户编号不存在,获取账户列表返回结果为空");
		try {
			int userId=0;
			getaccountlistbyuseridBean.setUserId(userId);
			getaccountlistbyuseridBean.setAppId("AutoTest");
			getaccountlistbyuseridCall.setData(getaccountlistbyuseridBean);
			getaccountlistbyuseridCall.callService();			
			Logger.verifyEquals(null,getaccountlistbyuseridCall.getAccountList(),"验证接口返回AccountList为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountListByUserId_003() {
		Logger.start(false,"用户编号为空,获取账户列表返回结果为空");
		try {
			int userId=0;
			//getaccountlistbyuseridBean.setUserId(userId);
			getaccountlistbyuseridBean.setAppId("AutoTest");
			getaccountlistbyuseridCall.setData(getaccountlistbyuseridBean);
			getaccountlistbyuseridCall.callService();			
			Logger.verifyEquals(null,getaccountlistbyuseridCall.getAccountList(),"验证接口返回AccountList为null");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountListByUserId_004() {
		Logger.start(false,"AppId为空,获取账户列表返回结果为空,提示AppId不能为空！");
		try {
			int userId=20000001;
			getaccountlistbyuseridBean.setUserId(userId);
			//getaccountlistbyuseridBean.setAppId("AutoTest");
			getaccountlistbyuseridCall.setData(getaccountlistbyuseridBean);
			getaccountlistbyuseridCall.callService();			
			Logger.verifyEquals("2",getaccountlistbyuseridCall.getStatuscode(),"验证接口返回Statuscode");	
			Logger.verifyEquals("AppId不能为空！",getaccountlistbyuseridCall.getMsg(),"验证接口返回错误提示信息");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}